package com.iweipan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.iweipan.R;
import com.iweipan.bean.REListBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by xyb on 2016/12/13.
 */

public class MoneyListAdapter extends BaseAdapter {
    private REListBean reListBean;
    private Context context;
    private int type;

    public MoneyListAdapter(int type, Context context) {
        this.reListBean = reListBean;
        this.context = context;
        this.type = type;
    }

    public void setReListBean(REListBean reListBean) {
        if (this.reListBean != null) {
            this.reListBean = null;
        }
        this.reListBean = reListBean;
        notifyDataSetChanged();
    }

    public void addReListBean(REListBean reListBean) {
        for (REListBean.ResultBean resultBean : reListBean.getResult()) {
            this.reListBean.getResult().add(resultBean);
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return (reListBean != null && reListBean.getResult().size() > 0) ? reListBean.getResult().size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return (reListBean != null && reListBean.getResult().size() > 0) ? reListBean.getResult().get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (viewHolder == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.rewtlistview_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        REListBean.ResultBean resultBean = (REListBean.ResultBean) getItem(position);
        int payType = resultBean.getPayType();
        if (payType == 401) {
            viewHolder.createText.setText("[" + "提现" + "]");
        } else if (payType == 402) {
            viewHolder.createText.setText("[" + "提现失败,返回金额" + "]");
        } else if (payType == 301) {
            viewHolder.createText.setText("[" + "充值" + "]");
        }
//        viewHolder.createInfo.setText("人民币/元");
        viewHolder.buyPrice.setText(String.valueOf(resultBean.getMoney())+"元");
        viewHolder.createTime.setText(resultBean.getAddTime());
        if (resultBean.getOrderType() == 9) {
            viewHolder.nowType.setText("充值成功");
        } else if (resultBean.getOrderType() == 12) {
            viewHolder.nowType.setText("提交到银联");
        } else if (resultBean.getOrderType() == 13) {
            viewHolder.nowType.setText("提现成功");
        } else if (resultBean.getOrderType() == 14) {
            viewHolder.nowType.setText("提现失败");
        } else if (resultBean.getOrderType() == 20) {
            viewHolder.nowType.setText("提现失败返回金额");
        }
        viewHolder.createMoney.setText(  String.valueOf(resultBean.getBalance())+"元");

        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.create_text)
        TextView createText;

        @BindView(R.id.buy_price)
        TextView buyPrice;
        @BindView(R.id.create_time)
        TextView createTime;
        @BindView(R.id.create_money)
        TextView createMoney;
        @BindView(R.id.now_type)
        TextView nowType;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


}
